/**
 * SceneTraveler - Singleton
 * @version 1.0
 * @author DavidRonai ( Makio ) http://flash-dungeon.com
 */

var SceneTraveler =(function()
{
	var instance;
	
	function init ()
	{
		//- PRIVATE VAR ---------------------------------
		var _container = null;
		var _currentScene = null;
		var _nextScene = null;
		
		//- PRIVATE FUNCTION ----------------------------	
		function onTransitionOutComplete()
		{
			//_container.removeChild(_currentScene);
			_currentScene.dispose();
			transitionToNextScene();
		}
		
		function transitionToNextScene () 
		{
			//_container.addChild(_nextScene);
			_nextScene.transitionIn();
			_currentScene = _nextScene;
		}
		
		return {
			
			//- PUBLIC VAR -----------------------------------------
			
			
			//- PUBLIC METHOD --------------------------------------
			init : function (container)
			{
				_container = container;
			},
			
			transitionTo : function (scene)
			{
				if (_currentScene) {
					_nextScene = scene;
					_currentScene.transitionOut( onTransitionOutComplete );
				}
				else {
					_nextScene = scene;
					transitionToNextScene();
				}
			},
			
			getCurrentScene: function()
			{
				return _currentScene;
			}
		}		
	}
 
	return {
		getInstance :function(){
			if (!instance){
				instance = init();
			}
			return instance; 
		}
	}
})();
